<template>
  <view class="tabbar-container" v-if="myIsShow">
    <block>
      <!-- 针对中间的导航栏  通过true来判断控制类名和样式 -->
      <view class="tabbar-item" v-for="(item, index) in tabbarList"
            :class="[item.centerItem ? 'center-item' : '']" @click="changeItem(item)" :key="index">
        <view class="item-top">
          <image :src="currentItem == item.id ? item.selectIcon : item.icon"></image>
        </view>
        <!-- 通过三元判断控制类名 达到控制选中和未选中的样式 -->
        <view class="item-bottom" :class="[currentItem == item.id ? 'item-active' : '']">
          <text>{{ item.text }}</text>
        </view>
      </view>
    </block>
  </view>
</template>

<script lang="ts">
// @ts-nocheck
import Vue from 'vue';

let app = getApp();
// 组件的书写符合easycom规范 无需引入直接使用
export default Vue.extend({
  props: {
    currentPage: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      myIsShow: app.globalData.myIsShow,
      show: false,
      currentItem: 1,
      tabbarList: [
        {
          id: 1,
          path: '/pages/index/index',
          icon: '/static/tabbar/indexa.png',
          selectIcon: '/static/tabbar/indexb.png',
          text: '首页',
          // 通过类名class控制样式大小
          centerItem: false
        },
        {
          id: 2,
          path: '/pages/orders/orders',
          icon: '/static/tabbar/ordersa.png',
          selectIcon: '/static/tabbar/ordersb.png',
          text: '订单',
          centerItem: false
        },
        {
          id: 3,
          path: '/pages/my/my',
          icon: '/static/tabbar/mya.png',
          selectIcon: '/static/tabbar/myb.png',
          text: '我的',
          centerItem: false
        },
      ],

      // 校园服务盒子
      navList: [],
      wxMpUrl: undefined,
      wxH5Url: undefined

      // url: undefined,   //第三方网站网址
    }
  },
  mounted() {
    this.currentItem = this.currentPage
    // this.getWxMpUrl()
    // this.wxMpUrl = uni.getStorageSync('wxMpUrl')
    // this.getWxH5Url()
    // console.log('this.wxH5Url', this.wxH5Url)
    // this.wxH5Url = uni.getStorageSync('wxMpUrl')
    // console.log('this.wxMpUrl', this.wxMpUrl)
    // 隐藏原来的tabBar导航栏
    uni.hideTabBar()
  },
  onShow() {

  },
  methods: {

    changeItem(item) {
      let _this = this
      //_this.currentItem = item.id;
      uni.switchTab({
        url: item.path
      })
      console.log('点击', item.id)
      if (item.id == 0) {
        _this.show = true

      }
    }
  }
})
</script>
<style lang="scss" scoped>
view {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.tabbar-container {
  position: fixed;
  bottom: 0rpx;
  left: 0rpx;
  width: 100%;
  height: 130rpx;
  // box-shadow: 0 0 5px #999;
  border-top: 2rpx solid #EBEBEB;
  background-color: #FFFFFF;
  display: flex;
  align-items: center;
  padding: 5rpx 0;
  color: #7E7E7E;
  z-index: 1001;

  /* 针对tabbar的统一处理 */
  .tabbar-item {
    width: 33.33%;
    height: 130rpx;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;

    .item-top {
      width: 70rpx;
      height: 70rpx;
      padding: 10rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    // 未被选中的导航栏字体
    .item-bottom {
      font-size: 20rpx;
      width: 100%;
      padding-bottom: 20rpx;
      color: #A5A5A5;
    }

    // 被选中的导航栏字体
    .item-active {
      color: #0278FD;
      padding-bottom: 20rpx;
    }
  }

  // 最中间的tabbar导航栏
  .center-item {
    display: block;
    position: relative;

    .item-top {
      flex-shrink: 0;
      width: 100rpx;
      height: 100rpx;
      position: absolute;
      top: -50rpx;
      left: calc(50% - 50rpx);
      // border-radius: 50%;
      // box-shadow: 0 0 5px #999;
      // background-color: rgb(240, 63, 131);
    }

    .item-bottom {
      position: absolute;
      bottom: 15rpx;
    }

    .item-active {
      position: absolute;
      // bottom: 5rpx;
      color: #4F91F2;
    }
  }

  // 弹窗
  .popup {
    width: 599rpx;

    .popup-up {
      border-radius: 16rpx 16rpx 0 0;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      padding: 20rpx 0;
      padding-top: 60rpx;
      background-color: #E9FFEE;

      .up-img {
        width: 350rpx;
        height: 350rpx;
      }

      .up-txt {
        color: #000000;
        font-size: 28rpx;
        padding-top: 24rpx;
        padding-bottom: 30rpx;
      }
    }

    // 关注
    .popup-card {
      color: #DEDEDE;
      font-size: 30rpx;
      width: 411rpx;
      height: 74rpx;
      line-height: 74rpx;
      text-align: center;
      background-color: #2BA245;
      border-radius: 50rpx;
      margin: 0 auto;
      margin-top: 30rpx;
    }

  }
}
</style>
